package com.example.lesson4

import android.content.Intent
import androidx.appcompat.app.AppCompatActivity
import android.os.Bundle
import android.util.Log
import android.widget.LinearLayout
import androidx.recyclerview.widget.LinearLayoutManager
import androidx.recyclerview.widget.RecyclerView

class MainActivity : AppCompatActivity() {
    val TAG = "MainActivity"
    var data = ArrayList<Teacher>()

    lateinit var adapter:TeacherAdapter

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_main)

        val name = intent.getStringExtra("user")
        if(name == null){
            startActivity(Intent(this,LoginActivity::class.java))
            finish()
        }

        Log.i(TAG,"login user = $name")

        adapter = TeacherAdapter()

        val recycler = findViewById<RecyclerView>(R.id.recycler)
        val manager = LinearLayoutManager(this)
        recycler.layoutManager = manager
        recycler.adapter = adapter

        //模拟加载数据
        loadData()
    }

    private fun loadData(){
        data.add(Teacher("Tom",45,"describe1",R.mipmap.tom))
        data.add(Teacher("Apple",52,"describe2",R.mipmap.apple))
        data.add(Teacher("Boy",32,"describe3",R.mipmap.jerry))
        data.add(Teacher("Cat",17,"describe4",R.mipmap.jiafei))
        data.add(Teacher("Tom",45,"describe1",R.mipmap.tom))
        data.add(Teacher("Apple",52,"describe2",R.mipmap.apple))
        data.add(Teacher("Boy",32,"describe3",R.mipmap.jerry))
        data.add(Teacher("Cat",17,"describe4",R.mipmap.jiafei))

        //告知 adapter
        adapter.setData(data)
    }
}